//#############################################################################
//#############################################################################
//This source file was written by Mert Dogar. If you have some questions about 
//the source code, please do not hesitate to ask me.
//The code is under GPL.
//Email: mertdogar@gmail.com , http://code.google.com/p/electron-cds
//#############################################################################
//#############################################################################

#ifndef COMPONENT_BASE_H
#define COMPONENT_BASE_H



#include "main.h"
#include "tvector.h"
#include "component_port.h"


class cbase
{
	public:
		enum e_angle {angle_0, angle_90, angle_180 , angle_270};
		
		cbase () {};
		cbase(std::string ctype,std::string cname , vector2 pos, e_angle my_angle = angle_0);
		cbase(vector2 start, vector2 end, float line_width, rgbcolor pcolor);
		~cbase() { };
		
		
		vector2 sroot;
		vector2 position;
		vector2 positionend;
		
		e_angle angle;
		std::string name;
		std::string type;
		void set_angle(int ang);
		int get_angle();
		
		int get_property_size();
		
		
		void set_property_visible(std::string str,bool val);
		bool get_property_visible(std::string str);
		
		void set_property_value(std::string str,std::string val);
		std::string get_property_value(std::string str);
		std::string get_property_value(int index);
		std::string get_property_name(int index);
		bool get_property_visible(int index);
		void set_property_name(int index,std::string val);
		
		bool isonme(vector2 cpos);
		bool draw(Cairo::RefPtr<Cairo::Context> cr, rgbcolor clr = torgbcolor(-1,-1,-1), float factor = 1, vector2 myroot =tovector2 (0,0));
		bool draw_area(Cairo::RefPtr<Cairo::Context> cr, rgbcolor clr = torgbcolor(-1,-1,-1), float factor = 1, vector2 myroot =tovector2 (0,0));
		bool select(Cairo::RefPtr<Cairo::Context> cr,vector2 mpos, rgbcolor mcolor,float factot = 1, vector2 sroot = tovector2 (0,0),bool isprint = false);
	private:
	

		
		
		struct shape
		{
			std::string type, text;
			rgbcolor color;
			vector2 c1,c2;
			vector2 additional;
		
		};
		
		struct property
		{
			std::string name,value;
			bool visible;
		};
		tvector<cport> ports;
		tvector<property> prop;
		tvector<shape> shm;
		bool load_shm(std::string cname);
		void add_port(vector2 pos);
		float scale(float rhs, float factor);
		float coscale(float rhs, float factor);
		int angle2int(e_angle ang);
		e_angle int2angle(int ang);
		bool int2bool(int integer);
};

#endif
